package com.lucaswangdev.controller;

import com.lucaswangdev.entity.User;
import com.lucaswangdev.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@Api(tags = "用户模块")
@RestController
@CrossOrigin(origins = "*")
@RequiredArgsConstructor
@RequestMapping("/user")
public class SwaggerDemoController {
    private final UserService userService;

    @ApiOperation("根据用户ID查询用户信息")
    @GetMapping("/{userId}")
    public ResponseEntity<User> queryUserById(@PathVariable Long userId) {
        return ResponseEntity.ok(userService.queryUserById(userId));
    }

    @ApiOperation("添加用户")
    @PostMapping
    public ResponseEntity<Long> addUser(@RequestBody User user) {
        return ResponseEntity.ok(userService.addUser(user));
    }

    @ApiOperation("更新用户")
    @PutMapping
    public ResponseEntity<String> updateUser(@RequestBody User user) {
        return ResponseEntity.ok(userService.updateUser(user));
    }

    @ApiOperation("根据用户ID删除用户")
    @DeleteMapping("/{userId}")
    public ResponseEntity<String> deleteUser(@PathVariable Long userId) {
        return ResponseEntity.ok(userService.deleteUser(userId));
    }
}
